//
//  HouseDetailView.m
//  Product_NEWS
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 FCH. All rights reserved.
//
#define WIDTH ([UIScreen mainScreen].bounds.size.width / 375)

#define HEIGHT ([UIScreen mainScreen].bounds.size.height / 667)

#import "HouseDetailView.h"
#import "NightModeHandle.h"
#import "UIImageView+WebCache.h"
@interface HouseDetailView()
@property(nonatomic,retain)UILabel *titleLabel;

@property (nonatomic, retain)UILabel *timeLabel;    //时间
@property (nonatomic, retain)UILabel *dateLabel;    //日期
@property (nonatomic, retain)UILabel *fromLabel;    //来自
@property (nonatomic, retain)UILabel *addressLabel;    //地方

@property (nonatomic, retain)UIImageView *bigImageView;
//内容
@end

@implementation HouseDetailView

-(instancetype)initWithFrame:(CGRect)frame
                HouseModel:(HouseModel *)
model

{
    self = [super initWithFrame:frame];
    
    if (self) {
        [self createSubViews:model];
    }
    
    return self;
    
}



-(void)createSubViews:(HouseModel *)model
{
    self.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20*WIDTH, 10*HEIGHT, 330*WIDTH, 80*HEIGHT)];
    self.titleLabel.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.textColor = [NightModeHandle shareNightModeHandle].titleColor;
    
    self.titleLabel.font = [UIFont boldSystemFontOfSize:22*SCREEN_WIDTH]; //加粗方法
    self.titleLabel.text = model.title;
    [self addSubview:self.titleLabel];
    [_titleLabel release];
    
    //日期
    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*WIDTH, 100*HEIGHT, 50*WIDTH, 20*HEIGHT)];
    self.dateLabel.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    self.dateLabel.font = [UIFont systemFontOfSize:14*SCREEN_WIDTH];
    self.dateLabel.textColor = [NightModeHandle shareNightModeHandle].wordColor;
    self.dateLabel.text = @"日期:";
    [self addSubview:self.dateLabel];
    [_dateLabel release];
    //时间
    
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(70*WIDTH, 100*HEIGHT, 110*WIDTH, 20*HEIGHT)];
    self.timeLabel.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    self.timeLabel.font = [UIFont systemFontOfSize:14*SCREEN_WIDTH];
    self.timeLabel.textColor = [NightModeHandle shareNightModeHandle].wordColor;
    self.timeLabel.text = model.date;
    
    [self addSubview:self.timeLabel];
    [_timeLabel release];
    //来自
    self.fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(190*WIDTH, 100*HEIGHT, 60*WIDTH, 20*HEIGHT)];
    self.fromLabel.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    self.fromLabel.text = @"来自:";
    self.fromLabel.font = [UIFont systemFontOfSize:14*SCREEN_WIDTH];
    self.fromLabel.textColor = [NightModeHandle shareNightModeHandle].wordColor;
    [self addSubview:self.fromLabel];
    [_fromLabel release];
    
    //地方
    self.addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(240*WIDTH, 100*HEIGHT, 100*WIDTH, 20*HEIGHT)];
    self.addressLabel.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    self.addressLabel.font = [UIFont systemFontOfSize:14*SCREEN_WIDTH];
    self.addressLabel.textColor = [NightModeHandle shareNightModeHandle].wordColor;
    self.addressLabel.text = model.laizhi;
    
    [self addSubview:self.addressLabel];
    [_addressLabel release];
    
    //详情图片
    self.bigImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20*WIDTH,130*HEIGHT,330*WIDTH,170*HEIGHT)];
    self.bigImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    
    NSURL *url = [NSURL URLWithString:model.ImageUrl];
    
    
    [self.bigImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"background.png"]];
    self.bigImageView.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    [self addSubview:self.bigImageView];
    [_bigImageView release];
    
    
    //内容
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20*WIDTH, 330*HEIGHT, 330*WIDTH, 300*HEIGHT)];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    self.contentLabel.font = [UIFont systemFontOfSize:16*SCREEN_WIDTH];
    self.contentLabel.textColor = [NightModeHandle shareNightModeHandle].titleColor;
    self.contentLabel.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    self.contentLabel.text = model.contents;
    
    // lable自适应高度
    CGRect frame = self.contentLabel.frame;
    frame.size.height = [[self class] heightForContentText:model.contents];
    self.contentLabel.frame = frame;
    
    [self addSubview:self.contentLabel];
    [_contentLabel release];
}

+ (CGFloat)heightForContentText:(NSString *)text
{
    CGSize size = CGSizeMake(330*WIDTH, 2000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16.0*SCREEN_WIDTH] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
    
    
}

@end
